package kr.hkit.powerjava.chapter12.work;

import java.util.Arrays;
import java.util.Comparator;

public class PersonTest {
	public static void main(String[] args) {
		Person[] arr = new Person[3];
		arr[0] = new Person("김태희", 180);
		arr[1] = new Person("이민정", 190);
		arr[2] = new Person("태연", 160);
		
		System.out.println("가장 키가 큰 사람은 " + getMaximum(arr));
		
		Arrays.sort(arr);
		prnArr(arr);
		int a = Arrays.binarySearch(arr, new Person("효린"));
		
		System.out.println(a>0?"Found "+ arr[a]:"Not Found");
	}
	
	private static void prnArr(Person[] arr) {
		for(Person p : arr){
			System.out.println(p);
		}
	}

	public static String getMaximum(Person[] array){
		Comparator<Person> hSort = new Comparator<Person>() {
			@Override
			public int compare(Person o1, Person o2) {
				return o1.getHeight()-o2.getHeight();
			}
		};
		Arrays.sort(array,hSort );
		return array[array.length-1].getName();
	}
}
